package com.yanqu.road.server.logic.activity.condition.tonbing;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.task.args.activity.TonBingRedPacketValueArgs;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;

import java.math.BigInteger;

public class TonBingCampBoxScoreCondition extends BaseActivityCondition {

    public TonBingCampBoxScoreCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        TonBingRedPacketValueArgs args = (TonBingRedPacketValueArgs) object;
        if(args.getActivityId() != getActivityConditionInfo().getActivityId()){
            return;
        }
        BigInteger value = BigInteger.valueOf(args.getValue());
        if(value.compareTo(getValue()) > 0){
            setValueNoSync(value);
        }
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.TonBingCampBoxScore.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.TonBingCampBoxScore.getValue(), handle);
    }
}
